var api = require('../../utils/api.js')

Page({
    data: {
        isLogin: false,
        list: [],
    },
    onLoad() {
        wx.getSetting({
            success: function(res){
                if (res.authSetting['scope.userInfo']) {
                    wx.getUserInfo({
                        success: function(res) {
                            console.log(res.userInfo)
                            //用户已经授权过
                       }
                    })
                }
            }
        })
    },
    onShow() {
        var isLogin = wx.getStorageSync('login');
        if (isLogin) {
            this.setData({ isLogin: true });
            wx.getStorage({
                key: 'user',
                success: (res) => {
                    this.setData({user: res.data});
                }
            });
        } else {
            this.setData({ isLogin: false });
        }
        
    },
    goGetUserInfo: function(e) {
        if (e.detail.userInfo){
            api.login();
        } else {
            //用户按了拒绝按钮
        }
    },
    goAddress() {
        wx.switchTab({ url: '/pages/my/address'});
    },
    goAbout() {
        wx.showModal({
            content: '樱花小站，专注跨境物流场景',
            showCancel: false,
            success: function (res) {}
        })
    } 
    // ,
    // goOthers() {
    //     wx.showActionSheet({
    //         itemList: ['友链1', '友链2', '友链3'],
    //         success: function(res) {
    //             console.log(res.tapIndex)
    //         }
    //     })
    // }
});